package com.ruoyi.web.controller.system;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Pay;
import com.ruoyi.system.service.IPayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 * 
 * @author ruoyi
 * @date 2023-06-30
 */
@Api(tags="订单管理")
@RestController
@RequestMapping("/system/pay")
public class PayController extends BaseController
{
    @Autowired
    private IPayService payService;

    /**
     * 查询订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pay pay)
    {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        return getDataTable(list);
    }

    /**
     * 导出订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Pay pay)
    {
        List<Pay> list = payService.selectPayList(pay);
        ExcelUtil<Pay> util = new ExcelUtil<Pay>(Pay.class);
        util.exportExcel(response, list, "订单管理数据");
    }
    @Anonymous
    @ApiOperation("获取机构剩余时间")
    /**
     * 获取订单管理详细信息
     */
    @GetMapping(value = "/get")
    public AjaxResult getInfoBy(@PathVariable("dept_id") Long dept_id)
    {
        Pay pay = payService.selectPayByDept(dept_id);
        Date date =new Date();
        long day = pay.getEndTime().getTime() - date.getTime();
        Map<String,Long> map = new HashMap<>();
        map.put("day",day);
        return success(map);
    }
    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(payService.selectPayById(id));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('system:pay:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pay pay)
    {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('system:pay:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pay pay)
    {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除订单管理
     */
    @PreAuthorize("@ss.hasPermi('system:pay:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(payService.deletePayByIds(ids));
    }
}
